package cn.jiadakeji.parent.controller;

import cn.jiadakeji.parent.common.core.controller.BaseController;
import cn.jiadakeji.parent.common.core.domain.AjaxResult;
import cn.jiadakeji.parent.dto.MyTermCourseDTO;
import cn.jiadakeji.parent.dto.CourseNextTimeDTO;
import cn.jiadakeji.parent.dto.TermCourseDTO;
import cn.jiadakeji.parent.service.TermCourseService;
import cn.jiadakeji.parent.vo.TermTimeCourseLeaveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author heyanfeng
 * @create 2022-03-11 10:55
 */
@Api(value = "班课信息", tags = {"班课信息接口"})
@RestController
@RequestMapping("/termCourse")
public class TermCourseController extends BaseController {

    @Autowired
    private TermCourseService termCourseService;

    @ApiOperation("获取学生班课信息")
    @GetMapping("/termCourse/{studentId}")
    public AjaxResult getTermCourse(
            @ApiParam("学生ID")
            @PathVariable("studentId") String studentId
    ) {

        startPage();
        MyTermCourseDTO myTermCourseDTO = termCourseService.getTerCourse(studentId);
        return AjaxResult.success(myTermCourseDTO);
    }

    @ApiOperation("获取班课详细信息")
    @GetMapping("/termDetail/{courseId}")
    public AjaxResult getTermDetail(
            @ApiParam("班课ID")
            @PathVariable("courseId") String courseId
    ) {
        TermCourseDTO termCourseDTO = termCourseService.getTermDetail(courseId);
        return AjaxResult.success(termCourseDTO);
    }

    @ApiOperation("学生请假")
    @PostMapping("/confirmLeave")
    public AjaxResult toLeave(
            @ApiParam("课程ID")
            @RequestParam("courseId") String courseId,
            @ApiParam("学生请假信息")
            @RequestBody TermTimeCourseLeaveVo courseLeaveVo
    )

    {
        Boolean aBoolean = termCourseService.toLeave(courseId,courseLeaveVo);
        return aBoolean ? AjaxResult.success() : AjaxResult.error("请假失败");
    }

    @ApiOperation("获取下一次上课时间")
    @GetMapping("/toLeave")
    public AjaxResult leaveTime(
            @ApiParam("课程ID")
            @RequestParam("courseId") String courseId
    ) {
        CourseNextTimeDTO studentLeaveDTO = termCourseService.leaveTime(courseId);
        return AjaxResult.success(studentLeaveDTO);
    }
}
